package com.mgr.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.mgr.dao.TransactionDao;
import com.mgr.model.Accounts;
import com.mgr.service.AccountService;
import com.mgr.service.CustomerService;
import com.mgr.service.OTPService;
import com.mgr.service.SmsService;
import com.mgr.service.TransactionService;

@Controller
public class InternalTransferController2 {

	@Autowired
	private AccountService accountService;

	@Autowired
	private CustomerService customerService;

	@Autowired
	private OTPService otpService;

	@Autowired
	private SmsService smsService;

	@Autowired
	private TransactionDao transactionDao;
	@Autowired
	private TransactionService transactionService;

	@RequestMapping("internaltransfer1")
	public ModelAndView setFormTransferStep1(HttpSession session,
			HttpServletRequest request) {

		ModelAndView modelAndView = new ModelAndView(
				"internaltransaction2.tile");
		if (session.getAttribute("user") == null) {
			session.invalidate();
			modelAndView.setViewName("login");
		} else {
			try {
				String str = request.getParameter("account");
				int accId = Integer.parseInt(str);

				Accounts account = accountService.getAccount(accId);
				session.setAttribute("accId1", account.getAccId());
				session.setAttribute("balance", account.getBalance());
				modelAndView.addObject("accId1", account.getAccId());
				modelAndView.addObject("balance", account.getBalance());

			} catch (Exception e) {
				System.out.println("Error convert string to number!");
				modelAndView.setViewName("internaltransaction2.tile");
			}
		}
		return modelAndView;

	}
}